package com.gx.admin.service;

import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import javax.validation.Valid;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.student.demo.entity.Teacher;
import com.student.demo.repository.TeacherRepository;

@Service
public class TeacherService {

 	@Resource
	private TeacherRepository teacherRepository;

	public List<Teacher> findByPage(Integer page, int i) {
		Sort sort = new Sort(Direction.DESC,"bAge");
		PageRequest p = new PageRequest(page,i,sort);
		 Page<Teacher> findAll = teacherRepository.findAll(p);
		return findAll.getContent();
	}

	public List<Teacher> findAll() {
		return teacherRepository.findAll();
	}

	@Transactional
	public void remove(Integer id) {
		teacherRepository.deleteById(id);
	}

	//添加老师的基本信息
		public Teacher addTeacher(Teacher teacher) {
			return teacherRepository.save(teacher);
		}

		@Transactional
		public Teacher add(Teacher car) {
			return teacherRepository.save(car);
		}
	
		public Teacher findOne(Integer id) {
			return teacherRepository.findBybId(id);
		}

//		public Teacher findByBid(Integer id) {
//			return teacherRepository.findBybId(id);
//		}

		public Teacher findBybId(Integer id) {
			return teacherRepository.findBybId(id);
		}
		
		//根据老师编号查询
		public Teacher findBnumber(String bname) {
			 return teacherRepository.findByBNumber(bname);
		}
}
